import table from '@/components/dt/table/render.js'
import Opt from '@/components/dt/info/Opt.js'

let _this = null
let unitObj = {
  NUMBER: '套',
  AMOUNT: '万',
  AREA: '㎡'
}
let labelObj = {
  NUMBER: '套数',
  AMOUNT: '金额',
  AREA: '面积'
}
let labelObj1 = {
  CLUETARGET: '线索',
  VISITOR: '来人',
  SUBSCRIPTION: '认购',
  CONTRACT: '签约',
  PAYMENT: '回款'
}
class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    let caseList = [
      {
        field: 'userName',
        title: '顾问姓名',
        minWidth: 150
      },
      {
        field: 'workNo',
        title: '顾问工号',
        minWidth: 150
      },
      {
        field: 'stateStr',
        title: '顾问状态',
        minWidth: 150
      }
    ]
    let companyList = [
      {
        field: 'affiliatedCompany',
        title: '所属子公司',
        minWidth: 150
      },
      {
        field: 'businessDivision',
        title: '所属事业处',
        minWidth: 150
      },
      {
        field: 'buildingName',
        title: '所属案场',
        minWidth: 150
      },
      {
        minWidth: 120,
        cell: {
          value: (row) => row.buildingStatus,
          text: {}
        },
        header: {
          filter: {
            title: '案场状态',
            key: 'status',
            select: {
              multiple: true,
              maxTagCount: 2,
              key: 'buildStatus'
            }
          }
        }
      },
      {
        field: 'userCount',
        title: '顾问人数',
        minWidth: 150
      }
    ]
    let handleList = [
      {
        field: 'handles',
        title: '操作项',
        fixed: 'right',
        minWidth: 120,
        align: 'center',
        cell: {
          btn: [
            {
              title: '查看目标',
              event: 'checkDetail'
            }
          ]
        }
      }
    ]
    let clueOrVisitorList = [
      {
        field: 'initValue',
        title: `初始目标(${_this.curState != 'PAYMENT' ? '组' : '万'})`,
        minWidth: 180,
        cell: {
          value: (row) => {
            return `${
              row.settingStatus == '未设定' ? row.settingStatus : row.initValue != null ? row.initValue : ''
            }${row.whether ? '(补设)' : ''}`
          },
          text: {}
        }
      },
      {
        field: 'adjustmentTarget',
        title: `调整目标(${_this.curState != 'PAYMENT' ? '组' : '万'})`,
        minWidth: 180
      },
      {
        field: 'diff',
        title: `调整差(${_this.curState != 'PAYMENT' ? '组' : '万'})`,
        minWidth: 180,
        slots: {
          default: (params, h) => {
            let diffValue = params.row.diff != null ? params.row.diff : '-'
            let color = diffValue > 0 ? '#D9001B' : diffValue < 0 ? '#70B603' : '#515a6e'
            let priceDVTmp = diffValue > 0 ? '+' + diffValue : diffValue < 0 ? diffValue : diffValue
            return table.cell.text(h, {
              value: `<span style=color:${color};margin-left:5px>${priceDVTmp}</span>`,
              isHtml: true,
              tipsTxt: diffValue
            })
          }
        }
      },
      {
        title: '调整次数',
        minWidth: 180,
        slots: {
          default: (params, h) => {
            let isTotal = params.row.userName == '汇总' ? true : false
            let count = params.row.updateNumber
            if (count && count != '0' && !isTotal) {
              return table.cell.btn(_this, h, {
                title: count || '-',
                event: 'checkTimes',
                data: params.row
              })
            } else {
              return table.cell.text(h, {
                value: count
              })
            }
          }
        }
      },
      {
        field: 'actual',
        title: `实际${labelObj1[_this.curState]}(${_this.curState != 'PAYMENT' ? '组' : '万'})`,
        minWidth: 180
      },
      {
        field: 'reach',
        title: '达成率',
        minWidth: 180
      }
    ]
    let subOrContractList = [
      {
        field: 'initValue',
        title: `初始目标(${unitObj[_this.otherState]})`,
        minWidth: 180,
        cell: {
          value: (row) => {
            return `${
              row.settingStatus == '未设定' ? row.settingStatus : row.initValue != null ? row.initValue : ''
            }${row.whether ? '(补设)' : ''}`
          },
          text: {}
        }
      },
      {
        field: 'adjustmentTarget',
        title: `调整目标(${unitObj[_this.otherState]})`,
        minWidth: 180
      },
      {
        title: `调整差(${_this.curState != 'PAYMENT' ? '组' : '万'})`,
        minWidth: 180,
        slots: {
          default: (params, h) => {
            let diffValue = params.row.diff || '-'
            let color = diffValue > 0 ? '#D9001B' : diffValue < 0 ? '#70B603' : '#515a6e'
            let priceDVTmp = diffValue > 0 ? '+' + diffValue : diffValue < 0 ? diffValue : diffValue
            return table.cell.text(h, {
              value: `<span style=color:${color};margin-left:5px>${priceDVTmp}</span>`,
              isHtml: true,
              tipsTxt: diffValue
            })
          }
        }
      },
      {
        title: '调整次数',
        minWidth: 180,
        slots: {
          default: (params, h) => {
            let isTotal = params.row.userName == '汇总' ? true : false
            let count = params.row.updateNumber
            if (count && count != '0' && !isTotal) {
              return table.cell.btn(_this, h, {
                title: count || '-',
                event: 'checkTimes',
                data: params.row
              })
            } else {
              return table.cell.text(h, {
                value: count
              })
            }
          }
        }
      },
      {
        field: 'actual',
        title: `实际${labelObj1[_this.curState]}${labelObj[_this.otherState]}(${unitObj[_this.otherState]})`,
        minWidth: 180
      },
      {
        field: 'reach',
        title: '达成率',
        minWidth: 180
      }
    ]
    if (_this.curState == 'SUBSCRIPTION' || _this.curState == 'CONTRACT') {
      if (_this.fromPage == 'case') {
        this.all = [...caseList, ...subOrContractList]
      } else {
        this.all = [...companyList, ...subOrContractList, ...handleList]
      }
    } else {
      if (_this.fromPage == 'case') {
        this.all = [...caseList, ...clueOrVisitorList]
      } else {
        this.all = [...companyList, ...clueOrVisitorList, ...handleList]
      }
    }
  }
}

export default Column
